<template>
  <!--卡片里的工具栏-->
  <div class="toolbar">
    <!--工具栏上的按钮做成一个插槽-->
    <slot name="buttonContainer"></slot>
    <!--工具栏上的搜索框-->
    <div class="input-container">
      <!--工具栏上自定义搜索框-->
      <slot name="customContainer"></slot>
      <!--工具栏固定搜索框，如果不需要也可以把它干掉-->
      <slot name="fixationContainer">
        <el-input placeholder="关键字搜索" class="keyword-input" size="medium" v-model="keyword"></el-input>
        <el-tooltip class="item search-item" effect="dark" content="搜索" placement="bottom">
          <button class="search" @click="sendKeyword">
            <i class="el-icon-search"></i>
          </button>
        </el-tooltip>
        <el-tooltip class="item empty-item" effect="dark" content="清空搜索条件" placement="top">
          <button class="search" @click="emptyQuery">
            <i class="el-icon-refresh"></i>
          </button>
        </el-tooltip>
      </slot>
    </div>
  </div>
</template>

<script>
  export default {
    name: "ToolBar",
    data() {
      return {
        keyword: ''
      }
    },
    methods: {
      /**
       * 当按钮被点击时，向父组件传递keyword
       */
      sendKeyword() {
        this.$emit("receiveKeyword", this.keyword);
      },
      /**
       * 清空查询条件
       */
      emptyQuery() {
        // 清空keyword
        this.keyword = '';
        // 清空其他条件
        this.$emit("emptyQuery");
      }
    }
  }
</script>

<style scoped>
  .toolbar {
    width: calc(100% - 150px);
    display: flex;
    justify-content: space-between;
    position: absolute;
    right: 1%;
    top: 10px;
    z-index: 999
  }


  .toolbar .btn-container {
    display: inline-block;
  }

  .toolbar .editor-container {
    padding: 0;
    width: 180px;
    z-index: 999;
    overflow: hidden;
    display: none;
    font-size: 14px;
    position: absolute;
    left: -30px;
    top: 36px;
  }

  .toolbar .editor-container .editor-item {
    list-style: none;
    width: 100%;
    height: 40px;
    line-height: 40px;
    padding-left: 5px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    background-color: #6d7ee9;
    color: #fff;
    z-index: 555;
  }
  .toolbar .editor-container .editor-item:nth-child(2) {
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
  }
  .toolbar .editor-container .editor-item:nth-child(3) {
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
  }
  .toolbar .editor-container .blank-item {
    height: 10px;
    background-color: transparent;
    border: none;
  }
  .toolbar .editor-container .editor-item:hover {
    color: #409EFF;
    background-color: #fff;
  }
  .toolbar .editor-container .blank-item:hover {
    background-color: transparent;
  }
  .toolbar .editor-container .editor-item:nth-child(2) {
    border: 1px solid #409EFF;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    border-bottom: none;
  }
  .toolbar .editor-container .editor-item:last-child {
    border: 1px solid #409EFF;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    border-top: none;
  }

  .toolbar .input-container .el-input {
    display: inline-block;
  }
  .keyword-input {
    width: 120px;
  }
  .toolbar .input-container {
    margin-left: 10px;
    display: inline-block;
    height: 100%;
    width: 500px;
    margin-right: 8px !important;
    text-align: right;
  }

  .search {
    vertical-align: bottom;
    margin-left: 5px;
    display: inline-block;
    width: 36px;
    height: 36px;
    line-height: 36px;
    border: 1px solid #ccc;
    border-radius: 5px;
    background-color: #fff;
    font-size: 18px;
    font-weight: bold;
    color: #666;
    cursor: pointer;
    outline: medium;
  }
  .search:hover {
    background-color: #c6e2ff;
    border-color: #ecf5ff;
  }

</style>

<style>

</style>